﻿using System;
using System.Collections.Generic;
using System.Text;
using Flexible.Interfaces;
using Flexible.Implementions.Helpers;

namespace Flexible.Implementions.Editors
{
    public class Int32Editor : ISettingEditor
    {
        object value;

        #region ISettingEditor Members

        public object Editor
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsValid
        {
            get
            {
                try
                {
                    Converter.ConvertTo(value, typeof(int));
                }
                catch
                {
                    return false;
                }
                return true;
            }
        }

        public string ErrorMessage
        {
            get
            {
                try { Converter.ConvertTo(value, typeof(int)); }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                return null;
            }
        }

        public object Value
        {
            get
            {
                return Converter.ConvertTo(value, typeof(int));
            }
            set
            {
                this.value = value;
            }
        }

        public string ToStringFormat()
        {
            return Converter.ConvertTo(value, typeof(int)).ToString();
        }

        #endregion
    }
}
